<h3 class='ui-state-active'><?php __("Danh mục sản phẩm")?></h3>
<div class="links">
	<ul>
		<li><a href="<?php echo $html->url(array('plugin' => 'products', 'controller'=>'manage_product_categories', 'action'=>'index'))?>"><?php __("Danh sách danh mục")?></a></li>
		<li><a href="<?php echo $html->url(array('plugin' => 'products', 'controller'=>'manage_product_categories', 'action'=>'add'))?>"><?php __("Tạo danh mục mới")?></a></li>
	</ul>
</div>
<h3 class='ui-state-active'><?php __("Sản phẩm theo danh mục")?></h3>
<?php 
    $nodes = ClassRegistry::init('products.ProductCategory')->children(1, false, array('id', 'name', 'alias', 'lft', 'rght'));
	$tree = ClassRegistry::init('products.ProductCategory')->transformToTree($nodes);
	//debug($tree); exit;
    function categoriesMenu($items, $html, $level){
    	$content = "<ul class='level-".$level."'>";
    	foreach ($items as $item) {
    	    if (isset($item['items'])) $class = "class='has_child'";
            else $class = "";
    		$content .= "<li ".$class.">";
    		if (isset($item['ProductCategory'])) {
        		$content .= "<a href='".$html->url(array('plugin' => 'products', 'controller' => 'manage_products', 'action' => 'index', 'root' => $item['ProductCategory']['alias']))."'>".$item['ProductCategory']['name']."</a>";
    		}
    		if (isset($item['items'])) {
    		    $level++;
    			$content .= categoriesMenu($item['items'], $html, $level);
    		}
            $content .= "</li>";
    	}
    	$content .= "</ul>";
    	return $content;
    }
?>
<?php //debug($tree); exit;?>
<div class="links">
    <?php $level = 1; ?>
	<?php echo categoriesMenu($tree, $html, $level);?>
</div>